home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 21 / GetCodecInfoApp ƒ / SpinCursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-15  |  2.9 KB  |  107 lines  |  [TEXT/MMCC]

  1. /*
  2.     File:        SpinCursor.c
  3.     
  4.     Contains:    Cursor code.
  5.  
  6.     Written by:    John Wang (and Think Reference people)
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        11/15/94    JW        New.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    "SpinCursor.h"
  23.  
  24. static short    gTickInterval;            //    number of ticks between a frame switch
  25. static long        gLastTick;                //    tick count of last call to SpinCursor
  26. static            acurHandle gFrameList;    //    our cursor list
  27.  
  28. /* ------------------------------------------------------------------------- */
  29.  
  30. /* Try to get the acur record and the cursor list for acurID, returning TRUE
  31.    if everything goes as planned. */
  32.  
  33. Boolean InitAnimatedCursors(short acurID, short interval)
  34. {
  35.     short    i=0;
  36.     short    cursID;
  37.     Boolean    noErrFlag = false;
  38.  
  39.     if ( (gFrameList = (acurHandle) GetResource('acur',acurID)) != nil ) {
  40.         noErrFlag = true;
  41.         while ( (i<(*gFrameList)->numberOfFrames) && noErrFlag ) {
  42.             cursID = (short) HiWrd((long) (*gFrameList)->frame[i]);
  43.             (*gFrameList)->frame[i] = GetCursor(cursID);
  44.             if ( (*gFrameList)->frame[i] )
  45.                 i++;                //    get the next one
  46.             else
  47.                 noErrFlag=false;    //    foo! we couldn't find the cursor
  48.         }
  49.     }
  50.     
  51.     if ( noErrFlag ) {
  52.         //    We have the cursors, now initialize the other fields
  53.         gTickInterval = interval;
  54.         gLastTick = TickCount();
  55.         (*gFrameList)->whichFrame = 0;
  56.     }
  57.     
  58.     return ( noErrFlag );
  59. }
  60.  
  61. /* ------------------------------------------------------------------------- */
  62.  
  63. /* Free up the storage used by the current animated cursor and all
  64.    of its frames */
  65.  
  66. void ReleaseAnimatedCursors()
  67. {
  68.     short    i;
  69.  
  70.     for ( i=0; i<(*gFrameList)->numberOfFrames; i++ )
  71.         ReleaseResource((Handle) (*gFrameList)->frame[i]);
  72.     ReleaseResource((Handle) gFrameList);
  73.  
  74.     SetCursor(&(qd.arrow));
  75. }
  76.  
  77. /* ------------------------------------------------------------------------- */
  78.  
  79. /*     Display the next frame in the sequence, if it's time. If not, do nothing.
  80.     This code should be pretty tight, but it might be possible to bum a few
  81.     instructions; ideally it should be as fast as possible. I doubt it will
  82.     be necessary to hand-hack it though.
  83.  
  84.     I chose this implementation over using a VBL task for the following reason:
  85.     the whole point of using an animated cursor is to let the user know that
  86.     your application is chugging away doing something. With this technique if
  87.     the applications shoots off to never-never land, the cursor will probably
  88.     stop spinning. A VBL task, on the other hand, would probably just sit and
  89.     merrily go on spinning away, the user none the wiser. */
  90.  
  91. void SpinCursor()
  92. {
  93.     register long  newTick;
  94.  
  95.     newTick = TickCount();
  96.  
  97.     //    Is it time?
  98.     if ( newTick < (gLastTick + gTickInterval) )
  99.         return;        //    nope
  100.  
  101.     //    Grab the frame, increment (and reset, if necessary) the count, and
  102.     //    display the new cursor
  103.     SetCursor(*((*gFrameList)->frame[(*gFrameList)->whichFrame++]));
  104.     if ( (*gFrameList)->whichFrame == (*gFrameList)->numberOfFrames )
  105.             (*gFrameList)->whichFrame = 0;
  106.     gLastTick = newTick;
  107. }